package com.ming.mallchat.common.user.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ming.mallchat.common.common.domain.vo.req.CursorPageBaseReq;
import com.ming.mallchat.common.common.domain.vo.resp.CursorPageBaseResp;
import com.ming.mallchat.common.common.utils.CursorUtils;
import com.ming.mallchat.common.user.mapper.UserFriendMapper;
import com.ming.mallchat.common.user.pojo.UserFriend;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserFriendDao extends ServiceImpl<UserFriendMapper, UserFriend> {
    public CursorPageBaseResp<UserFriend> getFriendList(Long uid, CursorPageBaseReq req) {
        return CursorUtils.getCursorPageByMysql(this, req, wrapper -> {
            wrapper.eq(UserFriend::getUid, uid);
        }, UserFriend::getUid);
    }

    public List<UserFriend> getByFriends(Long uid, List<Long> frilist) {
        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .in(UserFriend::getFriendUid, frilist)
                .list();
    }

    public UserFriend getByFriend(Long uid, Long targetUid) {
        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid, targetUid)
                .one();
    }

    public List<UserFriend> getUserFriend(Long uid, Long targetUid) {
        return lambdaQuery()
                .eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid, targetUid)
                .or()
                .eq(UserFriend::getUid, uid)
                .eq(UserFriend::getFriendUid, targetUid)
                .select(UserFriend::getId)
                .list();
    }
}
